package com.ruoyi.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.base.po.NamePo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.base.domain.MHolidays;
import com.ruoyi.base.service.IMHolidaysService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 员工请假Controller
 * 
 * @author ruoyi
 * @date 2024-08-09
 */
@RestController
@RequestMapping("/base/holidays")
public class MHolidaysController extends BaseController
{
    @Autowired
    private IMHolidaysService mHolidaysService;

    /**
     * 查询员工请假列表
     */
    @PreAuthorize("@ss.hasPermi('base:holidays:list')")
    @GetMapping("/list")
    public TableDataInfo list(MHolidays mHolidays)
    {
        startPage();
        List<MHolidays> list = mHolidaysService.selectMHolidaysList(mHolidays);
        return getDataTable(list);
    }
    //获取员工姓名
    @GetMapping("/getnamelist")
    public List<NamePo> namelist(MHolidays mHolidays)
    {
        List<NamePo> list = mHolidaysService.selectNameList();
        return list;
    }

    /**
     * 导出员工请假列表
     */
    @PreAuthorize("@ss.hasPermi('base:holidays:export')")
    @Log(title = "员工请假", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MHolidays mHolidays)
    {
        List<MHolidays> list = mHolidaysService.selectMHolidaysList(mHolidays);
        ExcelUtil<MHolidays> util = new ExcelUtil<MHolidays>(MHolidays.class);
        util.exportExcel(response, list, "员工请假数据");
    }

    /**
     * 获取员工请假详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:holidays:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mHolidaysService.selectMHolidaysById(id));
    }

    /**
     * 新增员工请假
     */
    @PreAuthorize("@ss.hasPermi('base:holidays:add')")
    @Log(title = "员工请假", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MHolidays mHolidays)
    {
        return toAjax(mHolidaysService.insertMHolidays(mHolidays));
    }

    /**
     * 修改员工请假
     */
    @PreAuthorize("@ss.hasPermi('base:holidays:edit')")
    @Log(title = "员工请假", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MHolidays mHolidays)
    {
        return toAjax(mHolidaysService.updateMHolidays(mHolidays));
    }

    /**
     * 删除员工请假
     */
    @PreAuthorize("@ss.hasPermi('base:holidays:remove')")
    @Log(title = "员工请假", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mHolidaysService.deleteMHolidaysByIds(ids));
    }
}
